﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using Portal.Interface;
using MyLib;

using System.Security.Cryptography;
using System.IO;
using System.Text;
using System.Globalization;
using PortalWebService;
using Portal;

namespace WebPortal
{
    public partial class SSOLogin : System.Web.UI.Page
    {
        IOrg _orgSrv = ServiceContainer.Instance().GetService<IOrg>();
        public string Login_UserOrPasswordInvalid = Resources.lang.Login_UserOrPasswordInvalid;
        public string Login_UserRequired = Resources.lang.Login_UserRequired;
        protected void Page_Load(object sender, EventArgs e)
        {
            userValidate();
        }

        private void userValidate()
        {
            string username = Request.QueryString["UserName"];
            if (username == null)
            {
                Response.Redirect("/Login.aspx");
            }
            if (!string.IsNullOrEmpty(username)) //从外部站点单点登录，如http://localhost:13910/Modules/Workflow/OpenForm.aspx?ProcessName=FWDY-%e4%b8%aa%e4%ba%ba%e8%b4%b9%e7%94%a8%e6%8a%a5%e9%94%80&Incident=1&Type=myapproval&username=b9JYBf%2fgZ1UUruLr%2fGZ72sB9bLgP2AfoTFlJb1MwJ8w%3d
            {
                username = EncryptHelper.DecryptTo(username);
            }

            if (!_orgSrv.CheckUser(username, ""))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "ce", "checkError();", true);
            }
            else
            {
                Portal.Logic.SSOLogic.SetLoginName(username);
                string TaskId = Request.QueryString["TaskId"];
                if (TaskId != null)
                {
                    Response.Redirect("/Modules/Workflow/OpenForm.aspx?TaskId=" + TaskId);
                }
                else
                {
                    Response.Redirect("Default.aspx");
                }

            }
        }
    }
}